package org.springframework.fusion.webscoket.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistration;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
	
	/**
	 * 设置连接地址和拦截器
	 */
	@Override
	public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
		WebSocketHandlerRegistration addHandler = registry.addHandler(webSocketMessage(), "/");
		addHandler.setAllowedOrigins("*");
	}

	/**
	 * 配置消息处理器
	 */
	@Bean
	public WebSocketConnection webSocketMessage() {
		WebSocketConnection webSocketMessage = new WebSocketConnection();
		return webSocketMessage;
	}

}
